package com.projecthost.wizaz.model;

import java.io.Serializable;
import java.util.List;

public class Category implements Serializable {

    private static final String KATEGORIA_PHP_URL_PART = "kategoria.php?kat=";

    private static final long serialVersionUID = -1047238541330085026L;

    private final Integer categoryId;
    private final String name;
    private final List<Category> subCategories;

    public Category(Integer categoryId, String name, List<Category> subCategories) {
        this.categoryId = categoryId;
        this.name = name;
        this.subCategories = subCategories;
    }

    public String getName() {
        return name;
    }

    public List<Category> getSubCategories() {
        return subCategories;
    }

    public String getBestUrl() {
        return KATEGORIA_PHP_URL_PART + categoryId + "&next=1&sort=999";
    }

    public static String getBestUrl(Integer categoryId, Integer pageCount) {
        return KATEGORIA_PHP_URL_PART + categoryId + "&next=" + pageCount + "&sort=999";
    }

    public String getWorstUrl() {
        return KATEGORIA_PHP_URL_PART + categoryId + "&next=1&sort=9999";
    }

    public static String getWorstUrl(Integer categoryId, Integer pageCount) {
        return KATEGORIA_PHP_URL_PART + categoryId + "&next=" + pageCount + "&sort=9999";
    }

    public String getFullUrl() {
        return KATEGORIA_PHP_URL_PART + categoryId + "&next=1";
    }

    public static String getFullUrl(Integer categoryId, Integer pageCount) {
        return KATEGORIA_PHP_URL_PART + categoryId + "&next=" + pageCount;
    }

    public static Integer getCategoryIdFromFullUrl(String fullUrl) {
        int startIndex = fullUrl.indexOf(KATEGORIA_PHP_URL_PART) + KATEGORIA_PHP_URL_PART.length();
        int endIndex = fullUrl.indexOf("&next=");
        return Integer.valueOf(fullUrl.substring(startIndex, endIndex));
    }

    public static String getSectionFromFullUrl(String fullUrl) {
        int endIndex = fullUrl.indexOf(KATEGORIA_PHP_URL_PART);
        return fullUrl.substring(0, endIndex);
    }
}
